package Compation;

import Utils.TreeNode;

public class goodNodes {
    int res = 0;

    public int goodNodes(TreeNode root) {
        if (root == null) {
            return res;
        }
        getNumOfgoodNodes(Integer.MIN_VALUE, root);
        return res;
    }

    private void getNumOfgoodNodes(int maxVal, TreeNode node) {
        if (node == null) {
            return;
        }
        if (node.val > maxVal) {
            res++;
            maxVal = node.val;
        }
        getNumOfgoodNodes(maxVal, node.left);
        getNumOfgoodNodes(maxVal, node.right);
    }
}
